package com.spring.lesson001.demo2;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;

/**
 * @author vhans
 */
public class Client {
    public static void main(String[] args) {
        String beanXml = "bean0012.xml";
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(beanXml);
        for (String beanName : Arrays.asList("user1", "user2", "user3", "user4", "user5")) {
            // 通过getAliases(String name)获取指定名称的bean的别名
            String[] aliases = context.getAliases(beanName);
            System.out.printf("beanName:%s,别名:[%s]%n", beanName, String.join(",", aliases));
        }
        System.out.println("方式二");
        // 通过getBeanDefinitionNames()获取所有bean名称
        for (String beanName : context.getBeanDefinitionNames()) {
            String[] aliases = context.getAliases(beanName);
            System.out.printf("beanName:%s,别名:[%s]%n", beanName, String.join(",", aliases));
        }
    }
}
